using System;

using Atomic.Libraries;

namespace Atomic.Structures
{
	[Serializable]
	public class Constituent
	{
		[NonSerialized] private int hashCode;

		public Constituent(Atom atom, double count)
		{
			if (atom == null)
			{
				throw new ArgumentNullException();
			}

			if (count < 0.0)
			{
				throw new ArgumentException();
			}

			Atom = atom;
			Count = count;
		}

		public bool Equals(Constituent other)
		{
			if (object.ReferenceEquals(other, null))
			{
				return false;
			}

			return EqualityHelper.Equals(this, other, new object[] { Atom, Count }, new object[] { other.Atom, other.Count }, hashCode, other.hashCode);
		}

		public override bool Equals(object other)
		{
			return Equals(other as Constituent);
		}

		public override int GetHashCode()
		{
			if (hashCode == 0)
			{
				hashCode = EqualityHelper.HashCode(new object[] { Atom, Count });
			}

			return hashCode;
		}

		public Atom Atom
		{
			get;
			private set;
		}

		public double Count
		{
			get;
			private set;
		}

		public static bool operator ==(Constituent object1, Constituent object2)
		{
			if (object.ReferenceEquals(object1, null))
			{
				if (object.ReferenceEquals(object2, null))
				{
					return true;
				}

				return false;
			}

			return object1.Equals(object2);
		}

		public static bool operator !=(Constituent object1, Constituent object2)
		{
			return !(object1 == object2);
		}
	}
}
